8.1 Declaring Decision Variables

Variable Names
Integer Variables
Where Conditions on Variables
Export Variable Values to Data Files
Export Variable Values to Excel Spreadsheet
Export Variable Values to Database

The decision variables are the elements under control of the model developer and their values determine the solution of the model. Decision variables in MPL are defined as they come in the input file. The name can be of any length. It starts with a letter, with the remainder consisting of letters and digits. MPL is case sensitive by default so you need to be careful to distinguish between upper and lower case letters. If you want MPL not to be case sensitive you can change the default by selecting MPL Language Dialog Box in the Options menu. See Chapter 4.9: The Options Menu for further details.

There are two types of decision variables: plain variables and vector variables (sometimes called subscripted variables). A plain variable is setup as a single column in the matrix that is sent to the LP solver. A vector variable, on the other hand, is setup as range of columns in the matrix.

The DECISION VARIABLES section is mainly used to define subscripted or vector variables, but plain variables can also be defined here. Vector variables must be defined before they are used in the model, but with plain variables it is optional. Plain variables can either be defined in the Decision Variable section or be introduced as they come into the model. It is recommended for larger models to define plain variables in the Decision Variable section in order to decrease the chance of errors occurring in the model. If you want to require plain variables to be defined you set the Plain Variables must be defined option in the MPL Language Dialog Box in the Options menu.

Variable Names

For each vector variable, enter the name and then specify what indexes are to be used by listing them inside brackets just after the name. For plain variables, enter just the name. You can use an optional semicolon to separate each variable definition.

Because variable names in most LP solvers are limited to eight characters and the subscripts for vector variables have to be included, only the first few characters are used when variable names are generated for solvers by MPL. To make sure there are no name conflicts, keep the first few characters distinct or use the becomes operator '->' to enter a shorter version of the name. This feature allows you to use long, descriptive names in your MPL model, and at the same time meet your LP package requirements for short names.

    DECISION VARIABLES
        Inventory[product,month]    ->  Invt ;
        Production[product,month]   ->  Prod ;

The preceding definition results in the generation of 108 variables (3 times 36). As an example of how these variables are generated, here is the list of all the Inventory variables:

    Invt1Jan     Invt2Jan     Invt3Jan
    Invt1Feb     Invt2Feb     Invt3Feb
    Invt1Mar     Invt2Mar     Invt3Mar
    Invt1Apr     Invt2Apr     Invt3Apr
    Invt1May     Invt2May     Invt3May
    Invt1Jun     Invt2Jun     Invt3Jun
    Invt1Jul     Invt2Jul     Invt3Jul
    Invt1Aug     Invt2Aug     Invt3Aug
    Invt1Sep     Invt2Sep     Invt3Sep
    Invt1Oct     Invt2Oct     Invt3Oct
    Invt1Nov     Invt2Nov     Invt3Nov
    Invt1Dec     Invt2Dec     Invt3Dec

Even though you can use fairly long names for variables in MPL you might sometimes want to use longer names or description for documentary purposes. MPL allows you to do that by following the definition with the keyword IS and a text description. If the description contains spaces you will need to enclose it with quotation marks.


    DECISION VARIABLES
       Production[product,month]
       IS "Production of each <product> per <month>";

Integer Variables

If some of the variables in the model are integer you can define them by putting the keyword INTEGER in front of the keyword VARIABLES. For binary variables use the keyword BINARY.

       INTEGER VARIABLES
           Production[product,month];

MPL allows you also to define integer and binary variables at the end of the model. For more information see Chapter 8.6: Integer and Binary Variables

Where Conditions on Variables

Sometimes you want to be able to limit the number of variables defined in a vector dependent on a data vector. In this case you can use a WHERE data condition following right after the definition of the vector. This will result in only those variables being created where the condition is met.

    DECISION VARIABLES
       Production[product,month]
       WHERE (Demand[product,month] > 0);

Export Variable Values to Data Files

After optimizing the problem, MPL can export the variable values to separate data files which can be used to report the solution back to the user. In the DECISION VARIABLES section, where you define the variable vector, enter the keyword EXPORT TO, followed by the keyword SPARSEFILE and parentheses containing the filename you want MPL to export to.

Prod[i,j]  EXPORT TO Sparsefile("prod.dat");

This will write the activity and the reduced cost values for each entry of the Prod variable vector to a text file in the standard sparse format. Since this file is a standard sparse data file, MPL can read these values back later into other models.

You can change which values will be exported by entering one or more of the following keywords directly after the keyword EXPORT: Activity, ReducedCost, ObjectCoeff, ObjectLower, ObjectUpper. If you want all of above entries you can use instead the ALL keyword.

     Prod[i,j]  EXPORT ALL TO Sparsefile("prod.dat");

MPL also allows you write solution values for variable vectors to data files in the same format as is used in the standard MPL solution files.

      Prod[i,j]  EXPORT TO Solutionfile("prod.sol");

When exporting to text files using the solution file format all the options the Solution File Options dialog box will have effect.

Export Variable Values to Excel Spreadsheet

MPL can also export the variable values to an Excel spreadsheet where it can be used to report the solution back to the user. Following the declaration of the variable vector, enter the keyword EXPORT TO, followed by the keyword EXCELRANGE and parentheses containing the Excel workbook name and the Excel range name you want to export to. For example:

    DECISION VARIABLES
       PatternCount[patterns]

          EXPORT TO EXCELRANGE("Cutstock.xls","PatCount");

In the above example, MPL will open the Excel spreadsheet Cutstock.xls, locate the range PatCount and then export the solution values for the variable vector PatternCount.

The EXCELRANGE command can also be used to export activity values for plain variables. If the range give contains more than one cell, only the first cell will be used for the exported value.

You can also export the data in sparse column format where the first columns store the values for the indexes followed by a column containing the variable values. In this case, you use the EXCELSPARSE command to specify that the data is to be written in a sparse format. For example:

    DECISION VARIABLES
       ExcessCuts[cuts]

          EXPORT TO EXCELSPARSE("Cutstock.xls","CutsTable", 4);

In this example the Excel range CutsTable contains four columns. The first column stores the values for the index Cuts followed by two columns containing the widths and the demand for each cut. The activities values for the ExcessCuts variable vector will be stored in the fourth column of the CutsTable range. If the Excel range contains the data as a Excel List there will be an extra row at the top of the range that contains the name of each column. MPL allows you to skip that row automatically by using the EXCELLIST command instead of the EXCELSPARSE command.

If you are writing multiple variable vectors to the same Excel spreadsheet, you can omit the workbook filename on all entries after the first one. Please note, that since variable exports are performed at a different time than imports, you will need to specify the spreadsheet workbook filename on the first export statement even if it is the same as the one you were importing from.

Export Variable Values to Database

After optimizing the problem, MPL can export the variable values to the database where it can be used to report the solution back to the user. Following the declaration of the variable vector, enter the keyword EXPORT TO, followed by the keyword DATABASE and parentheses containing the table name and the column name you want to export to.

Example:

      DECISION VARIABLES
        FactDepShip[factory,depot]

            EXPORT TO DATABASE("FactDep","Shipment");

In the above example, MPL will open the database table FactDep, locate the columns Shipment, FactID, and DepotID, and then export the solution values for the variable vector FactDepShip. For further information on exporting variable values please refer to Chapter 11.3: Export Variable Values to Database.


Back To Top | Maximal Home Page | Table of Contents | Previous Page | Next Page